<template>
  <div v-loading="loading">
    <BasicTable @register="registerTable" :rowSelection="rowSelection">

    </BasicTable>
    <AddForm @register="registerAddForm" @success="handleEdit" />
  </div>
</template>

<script lang="ts" name="system-user" setup>
  //ts语法
  import { ref, computed, unref } from "vue"
  import { BasicTable, TableAction, ActionItem, useTable, BasicColumn } from "/@/components/Table"
  import { useDrawer } from "/@/components/Drawer"
  import { useModal } from "/@/components/Modal"
  import { useMessage } from "/@/hooks/web/useMessage"
  import { columns, searchFormSchema } from "./data"
  import * as appApi from "/@/api/iam/app"
  import * as tenantApi from "/@/api/iam/tenant"
  import { Icon } from "/@/components/Icon"
  import { useGo } from "/@/hooks/web/usePage"
  // import { usePermission } from '/@/hooks/web/usePermission'
  // const { hasPermission } = usePermission();
  const [registerAddForm, { openModal: openAddForm }] = useModal()
  const { createMessage, createConfirm } = useMessage()
  const go = useGo()
  const selectRows = ref([])
  const loading = ref(false)
  const actionColumn: BasicColumn = {
    width: 150,
    title: "操作",
    dataIndex: "action",
    fixed: "right",
    slot: "tableActions",
    actions: (record) => [
      {
        label: "安装",
        // auth: 'sys:area:update',
        onClick: handleInstall.bind(null, record.id),
      }
    ],
    dropDownActions: (record: Recordable) => [
      
    ],
  }

  const [registerTable, { reload, updateTableDataRecord, rowSelection, getSelectRowKeys }] = useTable({
    title: "应用列表",
    api: appApi.pageApp,
    bordered: false,
    columns: columns,
    size: "small",
    formConfig: {
      baseColProps: { lg: 8, md: 24 },
      labelWidth: 80,
      schemas: searchFormSchema,
      showResetButton: false,
    },
    actionColumn,
    showTableSetting: true,
    useSearchForm: true,
    pagination: true,
    canResize: true,
    rowKey: "id",
    beforeFetch: (params) => {
      return Object.assign({ column: "createTime", order: "desc" }, params)
    },
  })

  const handleInstall = async (appId) => {
    try {
      loading.value = true
      await tenantApi.installApp({ appId })
      createMessage.success("安装成功，请移步到我的应用中查看")
    } finally {
      loading.value = false
    }
  }

  function handleEdit( appId ) {
    go('/console/microApp/edit/' + appId)

  }
</script>

<style scoped></style>
